package com.mei.allpowerfuladapter.utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

/**
 * Created by Administrator on 2015/9/23.
 */
public abstract class CommonAdapter<T> extends BaseAdapter {

    protected List<T> mDatas;
    protected Context mContext;
    protected LayoutInflater inflater;
    private int layoutId;

    public CommonAdapter(Context context,List<T> datas,int layoutId){
        this.mContext=context;
        this.mDatas=datas;
        this.inflater=LayoutInflater.from(context);
        this.layoutId=layoutId;
    }
    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public T getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent){
        ViewHolder holder=ViewHolder.get(mContext, convertView, parent, layoutId, position);
        T t= mDatas.get(position);
        convert(holder,t);
        return holder.getConvertView();
    }

    public abstract void convert(ViewHolder holder,T t);
}
